import 'dart:async';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../news_model.dart';
import '../home_page_viewmodel.dart';

class TopStoriesNotifier extends AsyncNotifier<List<NewsModel>> {
  final HomePageViewModel viewModel;

  TopStoriesNotifier({required this.viewModel});

  @override
  FutureOr<List<NewsModel>> build() async {
    if (viewModel.topStories.isNotEmpty) {
      return viewModel.topStories;
    }
    await viewModel.fetchLastest();
    return viewModel.topStories;
  }
}